package com.infore.remoteControl.entity.protocolEntity;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

import javax.persistence.*;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.web.multipart.MultipartFile;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * 协议类
 * @author Cold
 *
 */
@Entity
@Table(name="PROTOCOL")
@NamedQuery(name="Protocol.findAll", query="SELECT p FROM Protocol p")
public class Protocol implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name="PROTOCOL_ID")
	@GeneratedValue(generator = "uuidGenerator")
	@GenericGenerator(name = "uuidGenerator", strategy = "uuid") // UUID生成策略
	private String protocolId;
	
	/** 协议编号 **/
	@Column(name="CODE", unique = true, length = 10)
	private String code;
	
	/** 协议名称 **/
	@Column(name="NAME", unique = true, length = 20)
	private String name;
	
	/** 协议序号 **/
	@Column(name="NUMBERS", length = 20)
	private String numbers;
	
	/** 协议类型ID(与协议类型关联) **/
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE) 
	@JoinColumn(name = "PROTOCOL_TYPE_ID")
	@NotFound(action = NotFoundAction.IGNORE)
	private ProtocolType protocolType;
	
	/** 协议数据 **/
	@JsonIgnoreProperties(value = {"protocol"})
	@OneToMany(mappedBy = "protocol", cascade = CascadeType.ALL)
	@NotFound(action = NotFoundAction.IGNORE)
	private Set<ProtocolData> protocolData;
	
	// 协议与文件共同保存所需的属性
	@Transient
	private List<String> publishedDates; // 协议数据内发布日期集合
	
	@Transient
	private List<String> protocolDataIds; // 协议数据内ID集合
	
	@Transient
	private List<MultipartFile> files; // 文件集合
	
	@Transient
	private String protocolTypeIds;
	
	@Transient
	private String protocolTypeCode;
	
	@Transient
	private String protocolTypeName;
	
	public Protocol() {
	}
	
	public Protocol(String numbers) {
		super();
		this.numbers = numbers;
	}

	public Protocol(String protocolId, String code, String name, String numbers, ProtocolType protocolType,
			Set<ProtocolData> protocolData) {
		super();
		this.protocolId = protocolId;
		this.code = code;
		this.name = name;
		this.numbers = numbers;
		this.protocolType = protocolType;
		this.protocolData = protocolData;
	}



	public String getProtocolId() {
		return protocolId;
	}

	public void setProtocolId(String protocolId) {
		this.protocolId = protocolId;
	}

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getNumbers() {
		return this.numbers;
	}

	public void setNumbers(String numbers) {
		this.numbers = numbers;
	}

	public ProtocolType getProtocolType() {
		return protocolType;
	}

	public void setProtocolType(ProtocolType protocolType) {
		this.protocolType = protocolType;
	}

	public Set<ProtocolData> getProtocolData() {
		return protocolData;
	}

	public void setProtocolData(Set<ProtocolData> protocolData) {
		this.protocolData = protocolData;
	}

	public List<String> getPublishedDates() {
		return publishedDates;
	}

	public void setPublishedDates(List<String> publishedDates) {
		this.publishedDates = publishedDates;
	}

	public List<String> getProtocolDataIds() {
		return protocolDataIds;
	}

	public void setProtocolDataIds(List<String> protocolDataIds) {
		this.protocolDataIds = protocolDataIds;
	}

	public List<MultipartFile> getFiles() {
		return files;
	}

	public void setFiles(List<MultipartFile> files) {
		this.files = files;
	}

	public String getProtocolTypeIds() {
		return protocolTypeIds;
	}

	public void setProtocolTypeIds(String protocolTypeIds) {
		this.protocolTypeIds = protocolTypeIds;
	}

	public String getProtocolTypeCode() {
		return protocolTypeCode;
	}

	public void setProtocolTypeCode(String protocolTypeCode) {
		this.protocolTypeCode = protocolTypeCode;
	}

	public String getProtocolTypeName() {
		return protocolTypeName;
	}

	public void setProtocolTypeName(String protocolTypeName) {
		this.protocolTypeName = protocolTypeName;
	}
	
}